package com.yan.test.work.testphoto;

import android.content.Context;
import android.util.DisplayMetrics;


/**
 * Created by 闫文勇 on 2016/12/3.
 * 不用Avtivity的关于屏幕适配的工具
 */

public class SizeUtil {

    public static int dp2px(int px ){
        DisplayMetrics dm = AppGlobals.getApplication().getResources().getDisplayMetrics();
        float density  = dm.density;
        return (int)(density*px + 0.5f);
    }



    public static int getScreenWidth() {
        DisplayMetrics metrics = AppGlobals.getApplication().getResources().getDisplayMetrics();
        return metrics.widthPixels;
    }

    public static int getScreenHeight() {
        DisplayMetrics metrics = AppGlobals.getApplication().getResources().getDisplayMetrics();
        return metrics.heightPixels;
    }



    public static int dp2px( Context context ,int px ){
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        float density  = dm.density;
        return (int)(density*px + 0.5f);
    }



    public static int dp2px(float px ){
        DisplayMetrics dm = AppGlobals.getApplication().getResources().getDisplayMetrics();
        float density  = dm.density;
        return (int)(density*px + 0.5f);
    }


}
